package com.itqianfeng.smartmeeting.service.Impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itqianfeng.smartmeeting.entity.Booking;
import com.itqianfeng.smartmeeting.entity.Timeslot;
import com.itqianfeng.smartmeeting.entity.dto.BookingDTO;
import com.itqianfeng.smartmeeting.entity.vo.MyBooking;
import com.itqianfeng.smartmeeting.mapper.BookingMapper;
import com.itqianfeng.smartmeeting.service.BookingService;
import com.itqianfeng.smartmeeting.service.TimeslotService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookingServiceImpl extends ServiceImpl<BookingMapper, Booking>implements BookingService {
    @Autowired
    private BookingMapper bookingMapper;
    @Autowired
    private TimeslotService timeslotService;
    @Override
    public List<MyBooking> getMyBooking(Integer userId) {
        return bookingMapper.getMyBooking(userId);
    }

    @Override
    public Integer isBooking(Integer roomId, String startTime, String endTime) {
      return  bookingMapper.isBooking(roomId,startTime,endTime);
    }

    @Override
    public Boolean saveBooking(BookingDTO bookingDTO) {
        //需要先添加时间记录timeslot表，然后在进行添加预约记录
        Timeslot timeslot = new Timeslot();
        BeanUtils.copyProperties(bookingDTO,timeslot);
//        timeslot.setTimeQj(bookingDTO.getTimeQj());
//        timeslot.setStartTime(bookingDTO.getStartTime());
//        timeslot.setEndTime(bookingDTO .getEndTime());
//        timeslot.setUserYear(bookingDTO.getUserYear());
//        timeslot.setUserMonth(bookingDTO.getUserMonth());
//        timeslot.setUserDay(bookingDTO.getUserDay());
//        timeslot.setTimeLong(bookingDTO.getTimeLong());
        boolean timeFlag = timeslotService.save(timeslot);
        Booking booking = new Booking();
        BeanUtils.copyProperties(bookingDTO,booking);
//        booking.setRoomId(bookingDTO.getRoomId());
//        booking.setState(bookingDTO. getState());
//        booking.setUserId(bookingDTO.getUserId());
        booking.setTimeId(timeslot.getTimeId());
        int result = bookingMapper.insert(booking);
        return result>0?true:false;
    }
}
